#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
// 最大的位数不超过30位
const int N = 55, M = 35;
typedef long long LL;
LL f[N][N][M];
LL w[N];

int cmp(LL a[], LL b[])
{
    for (int i = M - 1; i >= 0; --i)
        if (a[i] > b[i])
            return 1;
        else if (a[i] < b[i])
            return -1;
    return 0;
}

void add(LL a[], LL b[])
{
    LL top = 0;
    for (int i = 0; i < M; ++i)
    {
        int tmp = a[i];
        a[i] = (tmp + b[i] + top) % 10;
        top = (tmp + b[i] + top) / 10;
    }
}

void mul(LL a[], LL b)
{
    LL top = 0;
    for (int i = 0; i < M; ++i)
    {
        LL tmp = a[i];
        a[i] = (tmp * b + top) % 10;
        top = (tmp * b + top) / 10;
    }
}

void print(LL a[])
{
    int k = M - 1;
    while (k && !a[k])
        --k;
    for (; k >= 0; --k)
        cout << a[k];
    cout << endl;
}

int main()
{
    int n;
    cin >> n;
    LL tt[M];
    for (int i = 1; i <= n; ++i)
        cin >> w[i];
    for (int len = 3; len <= n; ++len)
        for (int l = 1; l + len - 1 <= n; ++l)
        {
            int r = l + len - 1;
            f[l][r][M - 1] = 1;
            for (int k = l + 1; k < r; ++k)
            {
                memset(tt, 0, sizeof tt);
                tt[0] = w[l];
                mul(tt, w[r]);
                // if(l == 2 && k == 3 && r == 4)cout << "--", print(tt);
                mul(tt, w[k]);
                // if(l == 2 && k == 3 && r == 4) cout << "--", print(tt);
                // if(l == 2 && k == 3 && r == 4) cout << "---",print(tt), cout << w[l] * w[r] * w[k]<< endl;
                // cout << l << ' ' << r << endl;
                // cout << "tt:";print(tt);
                // cout << w[l] * w[r] * w[k] << endl;
                add(tt, f[l][k]);
                add(tt, f[k][r]);
                if (cmp(f[l][r], tt) > 0)
                    memcpy(f[l][r], tt, sizeof tt);
            }
        }
    print(f[1][n]);
    return 0;
}
